package mobile;

/**
 * Class responsible for separating the CSV files
 * 
 * @author kbailov
 * 
 */
public class BrandModelSeparator {

	private static final String COMMA = ",";

	private MobileType[] types;

	public BrandModelSeparator(String input) {
		String[] lines = input.split("\n");
		types = getTypePairs(lines);
	}

	public MobileType[] getTypes() {
		return types;
	}

	private MobileType[] getTypePairs(String[] lines) {
		if (lines == null || lines.length < 2) {
			// first line is informative and should be neglected
			return null;
		}

		MobileType[] inputTypes = new MobileType[lines.length - 1];
		for (int i = 1; i < lines.length; i++) {
			String[] idName = lines[i].split(COMMA);

			int id = Integer.parseInt(idName[0]);
			String name = idName[1];
			MobileType type = new MobileType(id, name);

			inputTypes[i - 1] = type;
		}

		return inputTypes;
	}

}
